FROM centos:7
MAINTAINER Aaron

RUN yum -y install curl \
  && curl http://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/CentOS-Base.repo \
  && yum makecache \
  && yum -y install epel-release \
  && yum -y update \
  && yum clean all

#Setting up systemd
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
ENTRYPOINT ["/usr/sbin/init"]
#CMD ["/usr/sbin/init"]

RUN yum install -y systemd* && yum clean all

RUN yum install -y yum-utils yum-plugin-ovl tar git curl bind-utils unzip wget vim ntp bash && yum clean all

# kerberos client
RUN yum install -y krb5-workstation && yum clean all

# initscripts (service wrapper for servicectl) is need othewise the Ambari is unable to start postgresql
RUN yum install -y initscripts && yum clean all

# Setup sshd
RUN yum install -y openssh-server openssh-clients && yum clean all \
  && systemctl enable ntpd \
  && systemctl enable sshd

RUN /bin/cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  && groupadd -r admin && useradd -g admin admin \
  && sed -i '/# End of file/a* soft nofile 65536\n* hard nofile 65536\nroot soft nofile 131072\nroot hard nofile 131072' /etc/security/limits.conf \
  && sed -i -e 's/^#DefaultLimitNOFILE.*/DefaultLimitNOFILE=1024000/' -e 's/^#DefaultLimitNPROC.*/DefaultLimitNPROC=1024000/' /etc/systemd/system.conf \
  && echo 'root:123456' |chpasswd \
  && sed -ri -e 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' -e 's/.*StrictHostKeyChecking ask/StrictHostKeyChecking no/' /etc/ssh/sshd_config \
  && ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa \
  && cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys \
  && chmod 700 ~/.ssh \
  && chmod 600 ~/.ssh/id_rsa \
  && chmod 644 ~/.ssh/authorized_keys \
  && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key \
  && ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key \
  && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ecdsa_key

#RUN curl -o /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq && chmod +x /usr/bin/jq

# jdk8
ADD jdk-8u311-linux-x64.tar.gz /usr/local
ENV JAVA_HOME /usr/local/jdk1.8.0_311
ENV JRE_HOME /usr/local/jdk1.8.0_311/jre
ENV PATH $PATH:$JAVA_HOME/bin

# jce https://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip
ADD jce_policy-8.zip $JAVA_HOME/jre/lib/security/
RUN cd $JAVA_HOME/jre/lib/security && unzip jce_policy-8.zip && rm -f jce_policy-8.zip && mv UnlimitedJCEPolicyJDK8/*jar . && rm -rf UnlimitedJCEPolicyJDK8

ADD etc/yum.conf /etc/yum.conf

ENV PS1 "[\u@docker-ambari \W]# "

